package com.icoolkj.mall.inventory.mapper;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.Date;

/**
 * @author icoolkj
 * @version 1.0
 * @description
 * @createDate 2025/01/16 13:52
 */
@Mapper
public interface InventoryMapper {

    @Select("SELECT inventory_quantity FROM inventory WHERE product_id = #{productId}")
    Integer getInventory(@Param("productId") Long productId);

    @Update("UPDATE inventory SET inventory_quantity = inventory_quantity - #{inventoryQuantity}, update_time=#{updateTime} WHERE product_id = #{productId}")
    int reduceInventory(@Param("productId") Long productId,
                    @Param("inventoryQuantity") Integer count, @Param("updateTime") Date updateTime);

}
